<template>
    <div>
        项目名称: <input type="text" v-model="ps.name">
        <input type="button" value="查询" @click="show()">
        <input type="button" value="批量启用" @click="px(sb,1)">
        <input type="button" value="批量禁用" @click="px(sb,0)">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td><input type="checkbox" v-model="sa" @change="showc"></td>
                    <td>项目名称</td>
                    <td>项目编号</td>
                    <td>服务时长</td>
                    <td>服务人数</td>
                    <td>佣金</td>
                    <td>项目说明</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
                 <tr v-for="o in data.plist" :key="o.kid">
                    <td><input type="checkbox" v-model="sb" :value="o.kid" @change="showb"></td>
                    <td>{{o.kname}}</td>
                    <td>{{o.bian}}</td>
                    <td>{{o.shi}}</td>
                    <td>{{o.num}}</td>
                    <td>{{o.price}}</td>
                    <td>{{o.shuo}}</td>
                    <td>{{o.flag==1?"启用":"禁用"}}</td>
                    <td><input type="button" value="删除" @click="shan(o.kid,true)"></td>
                </tr>
            </tbody>
        </table>
        一共<span>{{data.count}}</span>条
        每页<span>{{ ps.pagesize }}</span>条
        共<span>{{ps.pageindex}}/{{data.pagecount}}</span>页
        <input type="button" value="首页" @click="page(1)">
        <input type="button" value="上一页" @click="page(ps.pageindex-1)">
        <input type="button" :value="o" v-for="o in data.pagecount" @click="page(o)">
        <input type="button" value="下一页" @click="page(ps.pageindex+1)">
        <input type="button" value="尾页" @click="page(data.pagecount)">
        <input type="number" v-model="ps.pageindex">
        <input type="button" value="跳转" @click="page(ps.pageindex)">
        <select @change="pag">
            <option :value="o" v-for="o in lie" >{{o}}</option>
        </select>
    </div>
</template>

<script setup lang="ts">
import moment from 'moment';
import axios from 'axios';
import { onMounted, ref} from 'vue'
import {useRoute,useRouter} from 'vue-router'
import router from '@/router';
let ps:any = ref({
    pageindex:1,
    pagesize:2,
    name:'',
    
})
let lie:any = ref([2,3,4])
let sb:any = ref([])
let sa:any = ref(false)
let data:any=ref({
    plist:[],
    count:'',
    pagecount:''
})
const pag=(e:any)=>{
    ps.value.pageindex = 1
    ps.value.pagesize = e.target.value
    show()
}
const page=(val:any)=>{
    if(val>=1&&val<=data.value.pagecount)
    {
        ps.value.pageindex=val
    }
    show()
}
const showc=()=>{
    if(sa.value==true)
    {
        sb.value = data.value.plist.map((o:any)=>{return o.kid})
    }
    else
    {
        sb.value = []
    }
}
const showb=()=>{
    if(sb.value.length!=data.value.plist.length)
    {
        sa.value = false
    }
    else
    {
        sa.value = true
    }
}
onMounted(()=>{
    show()
})
const show=()=>{
    axios({
        url:'https://localhost:7265/api/Kang/ShiDTO',
        method:"get",
        params:ps.value
    })
    .then(res=>{
        Object.assign(data.value,res.data);
    })
}
const shan=(id:any,z:any)=>{
    if(!confirm("确定要删除吗"))
    {

    }   
    axios({
        url:'https://localhost:7265/api/Kang/Delete',
        method:'put',
        params:{id:id,z:z}
    })
    .then(res=>{
        if(res.data>0)
        {
            alert("删除成功")
            show()
        }
        else
        {
            alert("删除失败")
            return;
        }
    })
}
const px=(ids:any,z:any)=>{
    if(sb.value.length==0)
    {
        alert('必须选择一个')
        return;
    }
    if(!confirm("确定要修改吗"))
    {

    }   
    axios({
        url:'https://localhost:7265/api/Kang/Px',
        method:'put',
        params:{ids:sb.value.toString(),z:z}
    })
    .then(res=>{
        if(res.data>0)
        {
            alert("修改成功")
            sa.value = false
            sb.value = []
            show()
        }
        else
        {
            alert("修改失败")
             sa.value = false
            sb.value = []
            return;
        }
    })
}
</script>

<style scoped>

</style>